package com.gaohe.controller;

import com.gaohe.pojo.User;
import com.gaohe.service.UserService;
import com.gaohe.utils.Result;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/user")
@ResponseBody
public class UserController {
    @Autowired
    private UserService service;

    /**
     * 登录 根据用户名 和 密码查询
     * @param user
     * @param request
     * @param response
     * @return
     */
    @PostMapping("/login")
    public Result login(@RequestBody User user, HttpServletRequest request, HttpServletResponse response ) {
        Result result = service.login(user,request,response);
        return result;
    }

    /**
     * 获取验证码
     * @param session
     * @return
     */
    @GetMapping("/code")
    public Result getCode(HttpSession session){
        return service.getCode(session);
    }

    /**
     * 注册
     * @param user
     * @param session
     * @return
     */
    @PostMapping("/register")
    public Result register(@RequestBody User user,HttpSession session){
        return service.register(user,session);
    }

    /**
     * 退出登录
     * @param session
     * @return
     */
    @GetMapping("/loginOut")
    public Result loginOut(HttpSession session){
        return service.loginOut(session);
    }

    /**
     * 获取用户名
     * @param session
     * @return
     */
    @GetMapping("/getUserInfo")
    public Result getUserInfo(HttpSession session){
        return service.getUserInfo(session);
    }


}
